package com.smartjobs.action;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.smartjobs.bean.EducationalQualificationBean;
import com.smartjobs.bean.JobseekerBean;
import com.smartjobs.bean.SkillsBean;
import com.smartjobs.bean.WorkExperienceBean;
import com.smartjobs.model.EditJSProfileModel;

@SuppressWarnings("serial")
public class EditJSProfileAction extends ActionSupport {
	String name;
	String emailID;
	String dob;
	String mobileNumber;
	int eqID;
	int jssID;
	int expID;
	int skillID;
	String degreeName;
	String yearOfPassing;
	String aggregateMarks;
	String CompanyName;
	String years;
	String months;

	public String getMonths() {
		return months;
	}

	public void setMonths(String months) {
		this.months = months;
	}

	public int getSkillID() {
		return skillID;
	}

	public void setSkillID(int skillID) {
		this.skillID = skillID;
	}

	public String getCompanyName() {
		return CompanyName;
	}

	public void setCompanyName(String companyName) {
		CompanyName = companyName;
	}

	public String getYears() {
		return years;
	}

	public void setYears(String years) {
		this.years = years;
	}

	public String getDegreeName() {
		return degreeName;
	}

	public void setDegreeName(String degreeName) {
		this.degreeName = degreeName;
	}

	public String getYearOfPassing() {
		return yearOfPassing;
	}

	public void setYearOfPassing(String yearOfPassing) {
		this.yearOfPassing = yearOfPassing;
	}

	public String getAggregateMarks() {
		return aggregateMarks;
	}

	public void setAggregateMarks(String aggregateMarks) {
		this.aggregateMarks = aggregateMarks;
	}

	public int getExpID() {
		return expID;
	}

	public void setExpID(int expID) {
		this.expID = expID;
	}

	public int getJssID() {
		return jssID;
	}

	public void setJssID(int jssID) {
		this.jssID = jssID;
	}

	public int getEqID() {
		return eqID;
	}

	public void setEqID(int eqID) {
		this.eqID = eqID;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmailID() {
		return emailID;
	}

	public void setEmailID(String emailID) {
		this.emailID = emailID;
	}

	public String getDob() {
		return dob;
	}

	public void setDob(String dob) {
		this.dob = dob;
	}

	public String getMobileNumber() {
		return mobileNumber;
	}

	public void setMobileNumber(String mobileNumber) {
		this.mobileNumber = mobileNumber;
	}

	@SuppressWarnings("rawtypes")
	Map session = ActionContext.getContext().getSession();

	public String UpdateBasicDetails() {

		JobseekerBean jobseeker = new JobseekerBean();
		jobseeker.setJobSeekerID(Integer.parseInt(session.get("jobseekerID")
				.toString()));

		jobseeker.setName(name);
		jobseeker.setEmailID(emailID);

		int mNo = Integer.parseInt(mobileNumber);
		jobseeker.setMobileNumber(mNo);

		SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy");
		SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
		String dateOfBirth = "";
		try {
			Date date = format1.parse(dob);
			dateOfBirth = format2.format(date);
			jobseeker.setDob(dateOfBirth);
		} catch (ParseException e) {
			e.printStackTrace();
		}

		EditJSProfileModel.UpdateBasicDetails(jobseeker);
		return SUCCESS;

	}

	public String DeleteJSEQ() {
		// System.out.println("eqID: " + eqID);
		EditJSProfileModel.DeleteJSEQ(eqID);
		return SUCCESS;

	}

	public String DeleteJSSkill() {

		EditJSProfileModel.DeleteJSSkill(jssID);
		return SUCCESS;

	}

	public String DeleteJSWorkEx() {

		EditJSProfileModel.DeleteJSWorkEx(expID);
		return SUCCESS;

	}

	public String InsertJSEQ() {

		EducationalQualificationBean educationalQualification = new EducationalQualificationBean();

		educationalQualification.setAggregateMarks(aggregateMarks);
		educationalQualification.setDegreeName(degreeName);
		educationalQualification.setYearOfPassing(yearOfPassing);
		educationalQualification.setJobseekerID(Integer.parseInt(session.get(
				"jobseekerID").toString()));

		EditJSProfileModel.InsertJSEQ(educationalQualification);

		return SUCCESS;

	}

	public String InsertJSSkill() {
		System.out.println("SkillID: " + skillID);
		SkillsBean skill = new SkillsBean();
		skill.setJobseekerID(Integer.parseInt(session.get(
				"jobseekerID").toString()));
		skill.setMonths(months);
		skill.setSkillID(skillID);	
		EditJSProfileModel.InsertJSSkill(skill);
		return SUCCESS;

	}

	public String InsertJSWorkEx() {
		WorkExperienceBean workExperience = new WorkExperienceBean();
		workExperience.setCompanyName(CompanyName);
		workExperience.setJobseekerID(Integer.parseInt(session.get(
				"jobseekerID").toString()));
		workExperience.setYears(years);

		EditJSProfileModel.InsertJSWorkEx(workExperience);
		return SUCCESS;

	}
}
